package com.jhc.api.system.domain.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jhc.api.system.domain.Router;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
@Accessors(chain = true)
public class RouterVo extends Router {
    /**
     * 搜索值
     */
    @JsonIgnore
    private String searchValue;

    public static RouterVo convert(Router entity){
        RouterVo vo = new RouterVo();
        BeanUtils.copyProperties(entity,vo);
        return vo;
    }

    public static Router convert(RouterVo vo){
        Router entity = new Router();
        BeanUtils.copyProperties(vo,entity);
        return entity;
    }

    public static List<RouterVo> convertToVos(List<Router> entityList){
        if (CollectionUtils.isEmpty(entityList)){
            return new ArrayList<>();
        }
        return entityList.stream().map(RouterVo::convert)
            .collect(Collectors.toList());
    }
    public static List<Router> convert(List<RouterVo> entityList){
        if (CollectionUtils.isEmpty(entityList)){
            return new ArrayList<>();
        }
        return entityList.stream().map(RouterVo::convert)
            .collect(Collectors.toList());
    }
}
